﻿using AppFlat.Application.IService;
using AppFlat.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace AppFlat.Application.Service
{
    public class DevUserService : BaseService<DevUser>, IDevUserService
    {
        public bool ChangeState(int userId)
        {
            // sql:  abs（） 方法是取绝对值
            string sql = "update devuser set state=abs(state-1) where id=@id";

            SqlParameter[] sp = { new SqlParameter("@id", userId) };
            return Repostory.ExecuteNonQuery(sql, sp)==1;
        }

        public bool EFChangeState(int userId,int state)
        {

            var user = new DevUser() { Password="11",Name="111", Id = userId, State = state };
            Repostory.Update(user, "State");
            return UnitOfWork.SaveChanges() ;
        }
    }
}
